"use client";

import {strategyArmory} from "@/apis";
//提供策略装配组件，也就是我提供了一个按钮，点击这个按钮，就会调用策略装配的方法，这个方法会调用策略装配的接口，然后根据接口返回的结果，来判断是否装配成功
export function StrategyArmory(){
    //提供策略装配的方法
const strategyArmoryHandler = async()=>{
    const queryParams = new URLSearchParams(window.location.search);
    const strategyId=Number(queryParams.get("strategyId"));
    if (!strategyId){
        window.alert("请在请求地址中，配置 strategyId 值，如：http://localhost:3000/?strategyId=100006")
        return;
    }
    const res= await strategyArmory(strategyId);
   const {code,info} =await res.json();
   if (code != "0000") {
    window.alert("抽奖策略装配失败 code:" + code + " info:" + info)
    return;
}
}
   return (
    <div
    className="px-6 py-2 mb-8 text-white bg-blue-500 rounded-full shadow-lg hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-300"
    style={{cursor: "pointer"}}
    onClick={strategyArmoryHandler}
>
装配抽奖
    </div>
   )
}